import 'dart:convert';

import 'package:flutter/widgets.dart';
import 'package:window_example/data/message.dart';
import 'package:window_example/data/person.dart';


import '../interface/content_page.dart';
import '../util/print_util.dart';
import 'json_test.dart';

class DataListContent extends ContentPage {
  @override
  Widget getContent() {
    return const DataListPage();
  }
}

class DataListPage extends StatefulWidget {
  static const mTAG = "DataListPage";

  const DataListPage({super.key});

  @override
  State<DataListPage> createState() => _DataListPageState();
}

class _DataListPageState extends State<DataListPage> {
  static const mTAG = "_DataListPageState";

  @override
  Widget build(BuildContext context) {
    LoggerUtil.d("main  jsonString$jsonString", mTAG);
    Map<String, dynamic> map = json.decode(jsonString);
    LoggerUtil.d("main  map$map", mTAG);
    String jsonStr = json.encode(map);
    LoggerUtil.d("main  jsonStr$jsonStr", mTAG);
    Person person = Person.fromJson(map);
    LoggerUtil.d("main  person ${person.age} ", mTAG);
    LoggerUtil.d("main  person ${person.name}", mTAG);
    LoggerUtil.d("main  person ${person.email}", mTAG);

    String personJson = jsonEncode(person);
    LoggerUtil.d("main  personJson$personJson", mTAG);

    var person2 = jsonDecode(
      jsonString,
    );
    LoggerUtil.d("main  person2${person2}", mTAG);

    var cars = <ACar>[ACar(name: "保时捷", price: 500), ACar(name: "奔驰",price: 1000)];
    person.car = cars;
    LoggerUtil.d("main  person${person.toString()}", mTAG);
    var person3 = jsonEncode(person);
    LoggerUtil.d("main  person3${person3.toString()}", mTAG);
    // const number = 1;
    // var res = switch (number) {
    //   1 => 1,
    //   _ => -1
    // };
    // print(res);
    Map<String,dynamic> userBeanMap = jsonDecode(person3.toString());
    UserBean userBean = UserBean.fromJson(userBeanMap);
    Map<String,dynamic> userBeanMap1 = userBean.toJson();
    String  userBeanJson = jsonEncode(userBeanMap1);
    LoggerUtil.d("main  person4${userBean.toString()}", mTAG);
    return Text("map:$map");
  }
}
